#include "tcphelper.h"

TcpHelper::TcpHelper() {}

QByteArray TcpHelper::getUserIdForInformationTask(int userId)
{
    QByteArray sendCommand;
    QDataStream out(&sendCommand, QIODevice::WriteOnly);
    out << USER_ID_FOR_INFORMATION;
    out << userId;

    return sendCommand;
}

QByteArray TcpHelper::getUserIdForFriendListTask(int userId)
{
    QByteArray sendCommand;
    QDataStream out(&sendCommand, QIODevice::WriteOnly);
    out << USER_ID_FOR_FRIEND_LIST;
    out << userId;

    return sendCommand;
}

QByteArray TcpHelper::getUserIdForChatHistoryTask(int userId1,int userId2)
{
    QByteArray sendCommand;
    QDataStream out(&sendCommand, QIODevice::WriteOnly);
    out << USER_ID_FOR_CHAT_HISTORY;
    out << userId1;
    out << userId2;

    return sendCommand;
}

QByteArray TcpHelper::getInsertChatHistoryTask(ChatHistory history)
{
    QByteArray sendCommand;
    QDataStream out(&sendCommand, QIODevice::WriteOnly);
    out << INSERT_CHAT_HISTORY;
    out << history.user_one_id;
    out << history.user_two_id;
    out << history;

    return sendCommand;
}

QByteArray TcpHelper::getUpdateUserInformationTask(User user)
{
    QByteArray sendCommand;
    QDataStream out(&sendCommand, QIODevice::WriteOnly);
    out << UPDATE_USER_INFORMATION_WITH_ID;
    out << user.id;
    out << user;

    return sendCommand;
}

QByteArray TcpHelper::getInsertUserInformationTask(User user)
{
    QByteArray sendCommand;
    QDataStream out(&sendCommand, QIODevice::WriteOnly);
    out << INSERT_USER_INFORMATION;
    out << user;

    return sendCommand;
}

QByteArray TcpHelper::getInsertFriendRelationTask(int user_one_id,int user_two_id)
{
    QByteArray sendCommand;
    QDataStream out(&sendCommand , QIODevice::WriteOnly);
    out << INSERT_FRIEND_RELATION;
    out << user_one_id;
    out << user_two_id;

    return sendCommand;
}

QByteArray TcpHelper::getDeleteFriendRelationTask(int user_one_id,int user_two_id)
{
    QByteArray sendCommand;
    QDataStream out(&sendCommand , QIODevice::WriteOnly);
    out << DELETE_FRIEND_RELATION;
    out << user_one_id;
    out << user_two_id;

    return sendCommand;
}
